package org.leetcode.easy.leetcode203;

import org.leetcode.easy.ListNode;

public class Solution
{
    public ListNode removeElements(ListNode head, int val)
    {


        if (head==null)
        {
            return head;
        }

        ListNode dummy = new ListNode(-1,head);
        ListNode pre=dummy;
        ListNode cur=head;

        while (cur!=null)
        {
            if (cur.val==val)
            {
                pre.next=cur.next;
            }else {
                pre =pre.next;
            }

            cur=cur.next;
        }

        return dummy.next;

    }

    public static void main(String[] args) {
        Solution solution = new Solution();

        ListNode listNode = new ListNode(7, new ListNode(7, new ListNode(7, new ListNode(7, null))));

        ListNode node = solution.removeElements(listNode, 7);

    }
}
